package com.sjb.sixteen_journey_backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sjb.sixteen_journey_backend.common.CommonHandle;
import com.sjb.sixteen_journey_backend.common.R;
import com.sjb.sixteen_journey_backend.entity.*;
import com.sjb.sixteen_journey_backend.entity.vo.MyMapVo;
import com.sjb.sixteen_journey_backend.mapper.*;
import com.sjb.sixteen_journey_backend.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sjb.sixteen_journey_backend.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 共性表 服务实现类
 * </p>
 *
 * @author jcz
 * @since 2024-07-15
 */
@Service
public class CommonnessServiceImpl extends ServiceImpl<CommonnessMapper, Commonness> implements ICommonnessService {
    @Autowired
    private CommonnessMapper commonnessMapper;

    @Autowired
    private CommonHandle commonHandle;

    @Autowired
    private IMyTimeService myTimeService;

    @Autowired
    private MyTimeMapper myTimeMapper;

    @Autowired
    private IAirTicketService airTicketService;
    @Autowired
    private AirTicketMapper airTicketMapper;

    @Autowired
    private IHotelTicketService hotelTicketService;
    @Autowired
    private HotelTicketMapper hotelTicketMapper;

    @Autowired
    private IInsuranceTicketService insuranceTicketService;
    @Autowired
    private InsuranceTicketMapper insuranceTicketMapper;

    @Autowired
    private IOthersTicketService othersTicketService;
    @Autowired
    private OthersTicketMapper othersTicketMapper;

    @Autowired
    private IShareThingService shareThingService;
    @Autowired
    private ShareThingMapper shareThingMapper;

    @Autowired
    private IMyMapService myMapService;
    @Autowired
    private MyMapMapper myMapMapper;

    @Autowired
    private IComeFriendService comeFriendService;
    @Autowired
    private ComeFriendMapper comeFriendMapper;


    @Autowired
    private IShowTicketService showTicketService;
    @Autowired
    private ShowTicketMapper showTicketMapper;

    @Override
    public R<?> addCollection(Integer idStatus, Integer moduleId) {
        if (idStatus == null || moduleId == null) {
            return R.error("请填写数据");
        }
        try {
            //判断当前用户对当前文是否是收藏
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");

            Commonness myCollection = getMyCollectionAndBeLiked(idStatus, moduleId, userId);
            if (myCollection == null) {
                Commonness commonness = new Commonness();
                commonness.setUserId(userId);
                commonness.setStatus(idStatus);
                commonness.setModuleId(moduleId);
                commonness.setMyCollection(false);
                this.save(commonness);

                //为了触发 触发器
                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_collection", 1);
                return R.success(null, "收藏成功");
            }
            if (!myCollection.getMyCollection()) {//0：没有被收藏
                //把myCollectionAndBeLiked中my_collection对应的记录改为1
                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_collection", 1);
                //增加对应文的被收藏+1 触发器已经写好了
                return R.success(null, "收藏成功");
            } else {
                //把myCollectionAndBeLiked中my_collection对应的记录改为0
                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_collection", 0);

                //当当前用户对此文既不收藏也不喜欢的时候删除此条记录，避免造成数据库冗长
                myCollection = getMyCollectionAndBeLiked(idStatus, moduleId, userId);
                if(!myCollection.getMyBeLiked()&&!myCollection.getMyCollection()){
                    this.removeById(myCollection.getCommonnessId());
                }
                //增加对应文的被收藏 -1 触发器已经写好了
                return R.success(null, "取消收藏成功");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<?> addBeLiked(Integer idStatus, Integer moduleId) {
        if (idStatus == null || moduleId == null) {
            return R.error("请填写数据");
        }
        try {
            //判断当前用户对当前文是否是收藏
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");

            Commonness myCollection = getMyCollectionAndBeLiked(idStatus, moduleId, userId);
            if (myCollection == null) {
                Commonness commonness = new Commonness();
                commonness.setUserId(userId);
                commonness.setStatus(idStatus);
                commonness.setModuleId(moduleId);
                commonness.setMyBeLiked(false);
                this.save(commonness);

                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_be_liked", 1);
                return R.success(null, "点击喜欢成功");
            }
            if (!myCollection.getMyBeLiked()) {//0：没有被收藏
                //把myCollectionAndBeLiked中my_collection对应的记录改为1
                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_be_liked", 1);
                //增加对应文的被收藏+1 触发器已经写好了
                return R.success(null, "点击喜欢成功");
            } else {
                //把myCollectionAndBeLiked中my_collection对应的记录改为0
                changeCollectionAndBeLiked(idStatus, moduleId, userId, "my_be_liked", 0);
                //当当前用户对此文既不收藏也不喜欢的时候删除此条记录，避免造成数据库冗长
                myCollection = getMyCollectionAndBeLiked(idStatus, moduleId, userId);
                if(!myCollection.getMyBeLiked()&&!myCollection.getMyCollection()){
                    this.removeById(myCollection.getCommonnessId());
                }

                //增加对应文的被收藏 -1 触发器已经写好了
                return R.success(null, "取消喜欢成功");
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R getCollectionAndLikedByModuleId(Integer idStatus, Integer moduleId) {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            Commonness myCollection = getMyCollectionAndBeLiked(idStatus, moduleId, userId);
            if (myCollection == null) {
                return R.success(null, "获取用户收藏和喜欢成功，但是该用户没有收藏和喜欢");
            }
            return R.success(myCollection, "获取用户收藏和喜欢成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<MyMapVo>> showCollectionMap() {
        try {
            List<Integer> mapId=this.getCommonnessIds(6,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的地图");
            List<MyMap> myMaps = myMapMapper.selectBatchIds(mapId);
            List<MyMapVo> myMapVos = myMapService.getListMyMapVo(myMaps);
            return R.success(myMapVos,"获取用户所收藏的地图成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<MyMapVo>> showBeLikedMap() {
        try {
            List<Integer> mapId=this.getCommonnessIds(6,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的地图");
            List<MyMap> myMaps = myMapMapper.selectBatchIds(mapId);
            List<MyMapVo> myMapVos = myMapService.getListMyMapVo(myMaps);

            return R.success(myMapVos,"获取用户所喜欢的地图成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<MyTime>> showCollectionMyTime() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(0,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的此刻");
            List<MyTime> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                MyTime myTime = myTimeMapper.selectMyTimeWithImages(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =myTimeService.setCountAndFollow(myTime);
                myMaps.add(myTime);
            }

            return R.success(myMaps,"获取用户所收藏的此刻成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<MyTime>> showBeLikedMyTime() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(0,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的此刻");
            List<MyTime> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                MyTime myTime = myTimeMapper.selectMyTimeWithImages(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =myTimeService.setCountAndFollow(myTime);
                myMaps.add(myTime);
            }

            return R.success(myMaps,"获取用户所喜欢的此刻成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<AirTicket>> showCollectionAirTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(1,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的机票晒单");
            List<AirTicket> myMaps =  new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                AirTicket myTime = showTicketMapper.selectAirTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =airTicketService.setCountAndFollow(myTime);
                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所收藏的机票晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<AirTicket>> showBeLikedAirTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(1,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的机票晒单");
            List<AirTicket> myMaps =new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                AirTicket myTime = showTicketMapper.selectAirTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =airTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所喜欢的机票晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<HotelTicket>> showCollectionHotelTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(2,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的酒店晒单");
            List<HotelTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                HotelTicket myTime = showTicketMapper.selectHotelTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =hotelTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所收藏的酒店晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<HotelTicket>> showBeLikedHotelTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(2,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的酒店晒单");
            List<HotelTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                HotelTicket myTime = showTicketMapper.selectHotelTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =hotelTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所喜欢的酒店晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<InsuranceTicket>> showCollectionInsuranceTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(3,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的保险理赔晒单");
            List<InsuranceTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                InsuranceTicket myTime = showTicketMapper.selectInsuranceTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =insuranceTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所收藏的保险理赔晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<InsuranceTicket>> showBeLikedInsuranceTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(3,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的保险理赔晒单");
            List<InsuranceTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                InsuranceTicket myTime = showTicketMapper.selectInsuranceTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =insuranceTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所喜欢的保险理赔晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<OthersTicket>> showCollectionOthersTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(4,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的其他晒单");
            List<OthersTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                OthersTicket myTime = showTicketMapper.selectOthersTicketById(mapId.get(i),userId);

                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =othersTicketService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所收藏的其他晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<OthersTicket>> showBeLikedOthersTicker() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(4,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的其他晒单");
            List<OthersTicket> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                OthersTicket myTime = showTicketMapper.selectOthersTicketById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =othersTicketService.setCountAndFollow(myTime);


                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所喜欢的其他晒单成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public R<List<ShareThing>> showCollectionShareThings() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(5,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的爆料");
            List<ShareThing> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                ShareThing myTime = shareThingMapper.getAllShareThingById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =shareThingService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所收藏的爆料");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public R<List<ShareThing>> showBeLikedShareThings() {
        try {
            Map<String, Object> map = ThreadLocalUtil.get();
            Integer userId = (Integer) map.get("id");
            List<Integer> mapId=this.getCommonnessIds(5,"my_be_liked");
            if(mapId.size()<=0) return R.success(null,"该用户没有喜欢的爆料");
            List<ShareThing> myMaps = new ArrayList<>();
            for(int i=0; i<mapId.size(); i++){
                ShareThing myTime = shareThingMapper.getAllShareThingById(mapId.get(i),userId);
                List<String> strings = commonHandle.imageByStringToList(myTime.getPath());
                myTime.setImages(strings);

                //设置评论数量和当前用户对该用户是否关注
                myTime =shareThingService.setCountAndFollow(myTime);

                myMaps.add(myTime);
            }
            return R.success(myMaps,"获取用户所喜欢的爆料");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public R<List<ComeFriend>> showCollectionComeFriend() {
        try {
            List<ComeFriend> comeFriendList = new ArrayList<>();
            List<Integer> mapId=this.getCommonnessIds(7,"my_collection");
            if(mapId.size()<=0) return R.success(null,"该用户没有收藏的约伴");
            List<ComeFriend> myMaps = comeFriendMapper.selectBatchIds(mapId);
            for (ComeFriend comeFriend : myMaps){
                ComeFriend data = comeFriendService.getFriendTableById(comeFriend.getComeFriendId()).getData();
                comeFriendList.add(data);
            }
            return R.success(comeFriendList,"获取用户所收藏的约伴");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    public List<Integer> getCommonnessIds(Integer status, String  name) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        QueryWrapper<Commonness> wrapper = Wrappers.query();
        wrapper.eq("user_id", userId);
        wrapper.eq("status", status);
        wrapper.eq(name, true);
        List<Integer> timeId = new ArrayList<Integer>();
        List<Commonness> commonness = this.list(wrapper);
        if(commonness.size()<=0) return timeId;
        timeId = commonness.stream()
                .map(Commonness::getModuleId)
                .collect(Collectors.toList());
        return timeId;
    }

    /*@Override
    public R deleteMyTimeById(Integer status, Integer id) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        if (status == 0) {
            MyTime myTime = myTimeService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (myTimeService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除我的时刻成功");
                    }
                }
            }
            return R.error("删除我的此刻失败");
        } else if (status == 1) {
            AirTicket myTime = airTicketService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (airTicketService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除机票晒单成功");
                    }
                }
            }
            return R.error("删除机票晒单失败");
        } else if (status == 2) {
            HotelTicket myTime = hotelTicketService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (hotelTicketService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除酒店晒单成功");
                    }
                }
            }
            return R.error("删除酒店晒单失败");
        } else if (status == 3) {
            InsuranceTicket myTime = insuranceTicketService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (insuranceTicketService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除理赔晒单成功");
                    }
                }
            }
            return R.error("删除理赔晒单失败");
        } else if (status == 4) {
            OthersTicket myTime = othersTicketService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (othersTicketService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除其他晒单成功");
                    }
                }
            }
            return R.error("删除其他晒单失败");
        } else {
            ShareThing myTime = shareThingService.getById(id);
            if (userId.equals(myTime.getUserId())) {
                if (shareThingService.removeById(id)) {
                    if (commonHandle.deleteAssociationTable(myTime.getPath(), status, id)) {
                        return R.success(null, "删除爆料成功");
                    }
                }
            }
            return R.error("删除爆料失败");
        }
    }
*/
    @Override
    public <T> R<List<List<T>>> showByKeywords(String keywords) {
        try {
            List<List<T>> data = new ArrayList<List<T>>();
            QueryWrapper<MyTime> wrapper = Wrappers.query();
            wrapper.like("experience", keywords).or().like("title", keywords);
            List<MyTime> MyTimes = myTimeService.list(wrapper);
            List<MyTime> myTime1 = new ArrayList<>();
            for (MyTime myTime:MyTimes){
                R<MyTime> myTimeById = myTimeService.getMyTimeById(myTime.getMyTimeId(), false);
                myTime1.add(myTimeById.getData());
            }
            data.add((List<T>) myTime1);

            HashMap<String, Object> param = new HashMap<>();
            param.put("experience","%"+keywords+"%");
            List<AirTicket> airTickets = airTicketMapper.selectByMap(param);
            List<AirTicket> airTickets1 = new ArrayList<>();
            for (AirTicket myTime:airTickets){
                R<AirTicket> myTimeById = airTicketService.showAllAirTicketById(myTime.getAirTicketId(), false);
                airTickets1.add(myTimeById.getData());
            }
            data.add((List<T>) airTickets1);

            List<HotelTicket> hotelTickets = hotelTicketMapper.selectByMap(param);
            List<HotelTicket> hotelTickets1 = new ArrayList<>();
            for (HotelTicket myTime:hotelTickets){
                R<HotelTicket> myTimeById = hotelTicketService.showAllHotelTicketById(myTime.getHotelTicketId(), false);
                hotelTickets1.add(myTimeById.getData());
            }
            data.add((List<T>) hotelTickets1);

            List<InsuranceTicket> insuranceTickets = insuranceTicketMapper.selectByMap(param);
            List<InsuranceTicket> insuranceTickets1 = new ArrayList<>();
            for (InsuranceTicket myTime:insuranceTickets){
                R<InsuranceTicket> myTimeById = insuranceTicketService.showAllTicketByIdAndStatus(myTime.getInsuranceTicketId(), false);
                insuranceTickets1.add(myTimeById.getData());
            }
            data.add((List<T>) insuranceTickets1);

            List<OthersTicket> othersTickets = othersTicketMapper.selectByMap(param);
            List<OthersTicket> othersTickets1 = new ArrayList<>();
            for (OthersTicket myTime:othersTickets){
                R<OthersTicket> myTimeById = othersTicketService.showAllOthersTicketById(myTime.getOthersTicketId(), false);
                othersTickets1.add(myTimeById.getData());
            }
            data.add((List<T>) othersTickets1);

            List<ShareThing> shareThings = shareThingMapper.selectByMap(param);
            List<ShareThing> shareThings1 = new ArrayList<>();
            for (ShareThing myTime:shareThings){
                R<ShareThing> myTimeById = shareThingService.getShareThingById(myTime.getShareThingId(), false);
                shareThings1.add(myTimeById.getData());
            }
            data.add((List<T>) shareThings1);

            List<MyMap> myMaps = myMapMapper.selectByMap(param);
            List<MyMap> myMaps1 = new ArrayList<>();
            for (MyMap myTime:myMaps){
                R<MyMap> myTimeById = myMapService.showMapById(myTime.getMyMapId(), false);
                myMaps1.add(myTimeById.getData());
            }
            data.add((List<T>) myMaps1);
            return R.success(data,"操作成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    public <T> R<List<List<T>>> showByCityName(String keywords) {
        try {
            List<List<T>> data = new ArrayList<List<T>>();
            QueryWrapper<MyTime> wrapper = Wrappers.query();
            wrapper.like("experience", keywords).or().like("title", keywords);
            List<MyTime> MyTimes = myTimeService.list(wrapper);
            List<MyTime> myTime1 = new ArrayList<>();
            for (MyTime myTime:MyTimes){
                R<MyTime> myTimeById = myTimeService.getMyTimeById(myTime.getMyTimeId(), false);
                myTime1.add(myTimeById.getData());
            }
            data.add((List<T>) myTime1);

            HashMap<String, Object> param = new HashMap<>();
            param.put("map_name","%"+keywords+"%");
            List<MyMap> myMaps = myMapMapper.selectByMap(param);
            List<MyMap> myMaps1 = new ArrayList<>();
            for (MyMap myTime:myMaps){
                R<MyMap> myTimeById = myMapService.showMapById(myTime.getMyMapId(), false);
                myMaps1.add(myTimeById.getData());
            }
            data.add((List<T>) myMaps1);
            return R.success(data,"操作成功");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }




    private void changeCollectionAndBeLiked(Integer idStatus, Integer moduleId, Integer userId, String name, int num) {
        UpdateWrapper<Commonness> wrapper = Wrappers.update();
        wrapper.set(name, num);
        wrapper.eq("user_id", userId);
        wrapper.eq("status", idStatus);
        wrapper.eq("module_id", moduleId);
        commonnessMapper.update(null, wrapper);
    }

    private Commonness getMyCollectionAndBeLiked(Integer idStatus, Integer moduleId, Integer userId) {
//        Map<String,Object> map2 = new HashMap<>();
//        map2.put("user_id", userId);
//        map2.put("status", idStatus);
//        map2.put("module_id", moduleId);
//        List<Commonness> myCollectionAndBeLikeds = commonnessMapper.selectByMap(map2);

        QueryWrapper<Commonness> wrapper = Wrappers.query();
        wrapper.eq("user_id", userId);
        wrapper.eq("status", idStatus);
        wrapper.eq("module_id", moduleId);
        Commonness commonness = commonnessMapper.selectOne(wrapper);

        return commonness;
    }
}
